<template>
	<view class="detail" :style="{ '--color': vuex_config.themeColor1 }">
		<sww-swipe :list="banner" :indicatorDots="true"></sww-swipe>
		<view class="detail-box">
			<view class="box-top">
				<view class="box-title">{{ dataForm.name }}</view>
				<view class="box-price price_num" v-if="!!dataForm.product_stock[0]">
					<text
						v-if="dataForm.product_stock[current].integral > 0">{{ dataForm.product_stock[current].integral }}积分</text>
					<template v-if="dataForm.product_stock[current].price > 0">
						<text v-if="dataForm.product_stock[current].integral > 0">+</text>
						<text>{{dataForm.product_stock[current].price}}元</text>
					</template>
					<text class="u-font-24 u-m-l-10 c-99 td-lt"
						v-if="dataForm.market_price > 0">￥{{ dataForm.market_price }}</text>
					<!-- <view class="price-btn">已售{{dataForm.num}}</view> -->
				</view>
				<view class="box-price" v-else>
					<text>产品已下架</text>
					<!-- <view class="price-btn">已售{{dataForm.num}}</view> -->
				</view>
				<!-- <view class="box-tip">注:本商品不可退款</view> -->
				<!-- 	<view class="box-position">
					<view class="address">广州天河</view>
					<view class="location">
						<u-icon name="map-fill"></u-icon>
						<text>快速定位</text>
					</view>
				</view> -->
			</view>
			<view class="link"></view>
			<u-cell-item title="选择规格" @click="Submit"></u-cell-item>
			<view class="link"></view>
			<view class="product-detail" v-if="dataForm.details ? true : false">
				<view class="product-detail-title u-flex">
					<view class="icon"></view>
					<text class="title">产品详情</text>
				</view>
				<u-parse :html="dataForm.details"></u-parse>
			</view>
			<view class="" style="height: 200rpx;"></view>
		</view>
		<sww-goods-action :show="false">
			<view class="nav-box" @click="onTab">
				<u-icon size="36" name="home"></u-icon>
				<text class="u-font-24">首页</text>
			</view>
			<view class="nav-box" @click="$customer">
				<button open-type="contact" class="u-reset-button contact_btn"></button>
				<u-icon size="36" name="kefu-ermai"></u-icon>
				<text class="u-font-24">客服</text>
			</view>
			<view class="nav-btn" @click="Submit">立即兑换</view>
		</sww-goods-action>

		<sww-login></sww-login>
		<spec-popup v-model="show" :dataForm="dataForm" @changeSpec="changeSpec" @submit="submit"></spec-popup>
	</view>
</template>

<script>
	import specPopup from './components/specPopup.vue'
	import {
		uniLinkTo,
		uniNavigate,
		uniToast,
		uniCall
	} from '@/utils/uniPromise.js';
	export default {
		data() {
			return {
				current: 0,
				dataForm: {},
				show: false,
				banner: [],
				value: 1,
				paramsObj: {}
			};
		},
		components: {
			'spec-popup': specPopup
		},
		onLoad(options) {
			this.initData(options.id);
		},
		methods: {
			initData(id) {
				this.$loading()
				this.$resPost('GetMallProductDetailed', {
					pk_id: id
				}).then(res => {
					if (!res.data.product_stock || !res.data.product_stock[0]) {
						this.$hide()
						uni.showModal({
							title: '商品已下架',
							showCancel: false,
							success: () => {
								this.uniBack()
							}
						})
						return
					}
					let img = [];
					if (res.data.img) {
						this.banner = res.data.img.split(',').map(src => {
							return {
								img: src
							};
						});
					}
					this.dataForm = {
						...res.data
					}
					this.$hide()
				});
			},
			onTab(idx) {
				this.$linkTo('index');
			},
			changeSpec(index) {
				this.current = index
			},
			Submit() {
				this.$login('initData').then(() => {
					this.show = true;
				});
			},
			submit(item) {

				let url = '/package/integral/order/index'
				let params = {
					prodId: this.dataForm.pk_id,
					prodName: this.dataForm.name,
					price: item.price,
					name: item.name,
					stockId: item.pk_id,
					num: item.specNum,
					integral: item.integral,
				}
				// #ifdef  MP-BAIDU ||  MP-ALIPAY || MP-TOUTIAO
				this.paramsObj = {
					...params
				}
				this.$to(url)
				// #endif


				// #ifndef MP-ALIPAY || MP-BAIDU || MP-TOUTIAO	
				uniNavigate(url).then(res => {
					res.eventChannel.emit('acceptParams', {
						specParams: {
							...params
						}
					});
				});
				// #endif
			},
			// 客服
			$customer() {
				// #ifdef H5
				let phone = this.vuex_business.custom_tel;
				uniCall(phone);
				// #endif
			},
		}
	};
</script>

<style lang="scss" scoped>
	.detail {
		.nav-box {
			display: flex;
			flex-direction: column;
			align-items: center;
			flex: 1;
			position: relative;

			.contact_btn {
				position: absolute;
				opacity: 0;
				top: 20rpx;
				width: 70rpx;
				height: 70rpx;
			}
		}

		.nav-btn {
			flex: 3;
			height: 100%;
			background-color: var(--color);
			color: #fff;
			font-size: 32rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.detail-box {
			border-radius: 25rpx 25rpx 0 0;
			width: 100%;
			// position: fixed;
			// top: 587rpx;
			overflow: hidden;
			background-color: #fff;

			.box-top {
				padding: 30rpx;
			}

			.box-title {
				font-size: 30rpx;
				color: #333;
				padding-bottom: 10rpx;
				overflow: hidden; //超出的文本隐藏
				text-overflow: ellipsis; //溢出用省略号显示
				white-space: nowrap; //溢出不换行
			}

			.box-price {
				color: $sww-theme-price;
				font-size: 28rpx;
				font-weight: bold;
				display: flex;
				align-items: center;
				padding: 10rpx 0;

				// border-bottom: 1px solid #ccc;
				&.price_num {
					font-size: 30rpx;
				}

				.price-btn {
					color: #999;
					font-size: 20rpx;
					border-radius: 40rpx;
					margin-left: 20rpx;
					padding: 0 20rpx;
				}
			}

			.box-tip {
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box; //作为弹性伸缩盒子模型显示。
				-webkit-box-orient: vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
				-webkit-line-clamp: 2; //显示的行
				padding: 20rpx 0;
				border-bottom: 1px solid #ccc;
				font-size: 20rpx;
				color: #999;
			}

			.box-position {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 20rpx 0 0;
				color: #666;

				.address {}

				.location {
					display: flex;
					align-items: center;
				}
			}

			.link {
				height: 13rpx;
				width: 100%;
				background-color: #f5f5f5;
			}

			.product-detail {
				padding: 30rpx 30rpx 0;

				.icon {
					height: 35rpx;
					background-color: var(--color);
					width: 8rpx;
					border-radius: 8rpx;
				}

				.title {
					font-size: 32rpx;
					font-weight: bold;
					color: #333;
					margin-left: 10rpx;
				}
			}
		}
	}
</style>
